package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;

import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.web.page.TableDataInfo;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.dto.ScheduleAndDate;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.wfit.modules.infomanagement.domain.TBusDate;
import cn.edu.wfit.modules.infomanagement.service.ITBusDateService;


/**
 * 日期预约Controller
 * 
 * @author zhanghao
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/date")
public class TBusDateController extends BaseController
{
    @Autowired
    private ITBusDateService tBusDateService;

    /**
     * 查询日期预约列表
     */
    @RequiresPermissions("system:date:list")
    @GetMapping("/list")
    public TableDataInfo list(TBusDate tBusDate)
    {
        startPage();
        List<TBusDate> list = tBusDateService.selectTBusDateList(tBusDate);
        return getDataTable(list);
    }

    /**
     * 导出日期预约列表
     */
    @RequiresPermissions("system:date:export")
    @Log(title = "日期预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusDate tBusDate)
    {
        List<TBusDate> list = tBusDateService.selectTBusDateList(tBusDate);
        ExcelUtil<TBusDate> util = new ExcelUtil<TBusDate>(TBusDate.class);
        util.exportExcel(response, list, "日期预约数据");
    }

    /**
     * 获取日期预约详细信息
     */
    @RequiresPermissions("system:date:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tBusDateService.selectTBusDateById(id));
    }

    /**
     * 新增日期预约
     */
    @RequiresPermissions("system:date:add")
    @Log(title = "日期预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBusDate tBusDate)
    {
        return toAjax(tBusDateService.insertTBusDate(tBusDate));
    }

    /**
     * 修改日期预约
     */
    @RequiresPermissions("system:date:edit")
    @Log(title = "日期预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBusDate tBusDate)
    {
        return toAjax(tBusDateService.updateTBusDate(tBusDate));
    }

    /**
     * 删除日期预约
     */
    @RequiresPermissions("system:date:remove")
    @Log(title = "日期预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBusDateService.deleteTBusDateByIds(ids));
    }

    /**
     * 根据日期查询详细信息
     */
    @RequiresPermissions("system:date:query")
    @GetMapping(value = "/date/{date}")
    public AjaxResult getInfoByDate(@PathVariable("date") String date) {
        List<ScheduleAndDate> scheduleAndDates = tBusDateService.selectTBusDateByDate(date);
        return success(scheduleAndDates);
    }
}
